<?php

namespace app\Admin\model;

use think\Model;
use think\Db;

class Do_register extends Model
{
    public function index($data)
    {
        $username = $data['Name'];
        $password = $data['Password'];
        $relname = $data['Relname'];
        $role = $data['Role'];
        $class = $data['Class'];

        //根据角色对应不同插入操作
        if($role == 'student')
        {
            $result = Db::table('student')->insert([
                'User_name'=>$username,
                'User_password'=>$password,
                'Class'=>$class,
                'Rel_name'=>$relname
            ]);
        }else{
            $result = Db::table('teacher')->insert([
                'User_name'=>$username,
                'User_password'=>$password,
                'Class'=>$class,
                'Rel_name'=>$relname
            ]);
        }
        //返回控制器
        if ($result) {
            return 1; //插入成功
        } else {
            return 2; //插入失败
        }
    }
}

?>